/**
	@file memtest.S
	@author Andrew D. Zonenberg
	@brief Does some dummy stuff with RAM
 */
 
.set noreorder					/*	Prevent any optimizations from reordering instructions!
									We want exe to exactly match source! */

/*
	Program entry point
 */
.section .startup.bootvec, "ax", @progbits 
.globl _start
_start:
	
	/*	Make sure we have a valid stack pointer. Just stick it near the end of ram for now.
		Restriction - must be uncached since cache miss handling isn't implemented in the CPU as of r120.
		Current RAM is a000:0000 to a000:1fff
		*/
	lui		$sp, 0xa000
	addiu	$sp, 0x1ffc
	
	/*	get address of main function in kseg1 by subtracting 0x2000:0000*/
	la		$k0, foobar
	lui		$k1, 0x2000
	subu	$k0, $k0, $k1
	
	/* Call the main function */
	jalr	$k0
	nop
	
.infloop:							/*	busy-wait forever */
	j			.infloop
	nop

/*
	Main application code
 */
.section .startup, "ax", @progbits 
.globl foobar
foobar:
	la			$t0, LEDBANKA		/*	LED array */
	li			$t1, 0x55
	sw			$t1, 0($t0)

	jr			$ra
	nop
	nop
